{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "<a href=\"https://colab.research.google.com/drive/11jE0hlhnp-ryKqu7LQARvMAQOeK2qdj1?usp=sharing\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"></a>"
      ],
      "metadata": {
        "id": "YJjhKGPnBfwF"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Decomposed Prompting"
      ],
      "metadata": {
        "id": "6VN5ZzhPZYvD"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "id": "6IJNszbK7i0r"
      },
      "outputs": [],
      "source": [
        "!pip install -qU google-generativeai"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import google.generativeai as genai\n",
        "import getpass"
      ],
      "metadata": {
        "id": "Iy9H_YgcZerX"
      },
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "Get free-tier Google's Gemini API Key here: https://aistudio.google.com/app/apikey"
      ],
      "metadata": {
        "id": "uJd2pOm_ZX_b"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "API_KEY = getpass.getpass(\"Enter your Google API key: \")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "X6ySKV9QZiv_",
        "outputId": "8f3b9999-a027-41b9-e8dc-a4efbaa8885f"
      },
      "execution_count": 7,
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Enter your Google API key: ··········\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "genai.configure(api_key=API_KEY)"
      ],
      "metadata": {
        "id": "12aLTtNkaMUZ"
      },
      "execution_count": 9,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "class SymbolicMemory:\n",
        "    \"\"\"Tracks intermediate results and context\"\"\"\n",
        "    def __init__(self):\n",
        "        self.memory = {}\n",
        "\n",
        "    def store(self, key, value):\n",
        "        self.memory[key] = value\n",
        "\n",
        "    def retrieve(self, key):\n",
        "        return self.memory.get(key)\n",
        "\n",
        "    def get_all(self):\n",
        "        return self.memory.copy()\n",
        "\n",
        "    def __str__(self):\n",
        "        return \"\\n\".join([f\"{k}: {v}\" for k, v in self.memory.items()])\n",
        "\n",
        "class DecomposedPromptingAgent:\n",
        "    def __init__(self):\n",
        "        self.model = genai.GenerativeModel(\"gemini-2.0-flash-exp\")\n",
        "        self.memory = SymbolicMemory()\n",
        "\n",
        "    def identify_subtasks(self, task):\n",
        "        \"\"\"Step 1: Identify sub-tasks\"\"\"\n",
        "        prompt = f\"\"\"Break down this complex task into 3-6 smaller sub-tasks.\n",
        "        Each sub-task should be specific and focused.\n",
        "\n",
        "        Task: {task}\n",
        "\n",
        "        List sub-tasks numbered:\"\"\"\n",
        "\n",
        "        response = self.model.generate_content(prompt).text\n",
        "\n",
        "        # Parse sub-tasks\n",
        "        subtasks = []\n",
        "        for line in response.split(\"\\n\"):\n",
        "            line = line.strip()\n",
        "            if line and (line[0].isdigit() or line.startswith(\"-\")):\n",
        "                subtask = line.lstrip(\"0123456789.-) \").strip()\n",
        "                if subtask and len(subtask) > 10:\n",
        "                    subtasks.append(subtask)\n",
        "\n",
        "        return subtasks\n",
        "\n",
        "    def create_specialized_prompt(self, subtask, task_context):\n",
        "        \"\"\"Step 2: Create tailored prompt for sub-task\"\"\"\n",
        "        memory_context = str(self.memory) if self.memory.get_all() else \"None yet\"\n",
        "\n",
        "        prompt = f\"\"\"Original Task: {task_context}\n",
        "\n",
        "        Current Sub-Task: {subtask}\n",
        "\n",
        "        Previously Computed Results:\n",
        "        {memory_context}\n",
        "\n",
        "        Solve this sub-task. Be specific and show your work:\"\"\"\n",
        "\n",
        "        return prompt\n",
        "\n",
        "    def solve_subtask(self, subtask, task_context, subtask_id):\n",
        "        \"\"\"Step 3: Solve individual sub-task\"\"\"\n",
        "        specialized_prompt = self.create_specialized_prompt(subtask, task_context)\n",
        "\n",
        "        response = self.model.generate_content(specialized_prompt).text\n",
        "        result = response.strip()\n",
        "\n",
        "        # Store in symbolic memory\n",
        "        self.memory.store(f\"subtask_{subtask_id}\", result)\n",
        "\n",
        "        return result\n",
        "\n",
        "    def integrate_results(self, task, subtasks, results):\n",
        "        \"\"\"Step 4: Coordinate and integrate all sub-task results\"\"\"\n",
        "        subtask_summary = \"\\n\\n\".join([\n",
        "            f\"Sub-task {i+1}: {subtask}\\nResult: {result}\"\n",
        "            for i, (subtask, result) in enumerate(zip(subtasks, results))\n",
        "        ])\n",
        "\n",
        "        prompt = f\"\"\"Original Task: {task}\n",
        "\n",
        "        Sub-task Results:\n",
        "        {subtask_summary}\n",
        "\n",
        "        Integrate these results into a comprehensive final answer:\"\"\"\n",
        "\n",
        "        response = self.model.generate_content(prompt).text\n",
        "        return response.strip()\n",
        "\n",
        "    def solve(self, task):\n",
        "        \"\"\"Main decomposed prompting pipeline\"\"\"\n",
        "        print(f\"\\n{'='*60}\")\n",
        "        print(f\"🧩 Decomposed Prompting\")\n",
        "        print(f\"{'='*60}\")\n",
        "        print(f\"Task: {task}\\n\")\n",
        "\n",
        "        # Reset memory\n",
        "        self.memory = SymbolicMemory()\n",
        "\n",
        "        # Step 1: Identify sub-tasks\n",
        "        print(f\"{'─'*60}\")\n",
        "        print(f\"STEP 1: Identifying Sub-Tasks\")\n",
        "        print(f\"{'─'*60}\\n\")\n",
        "\n",
        "        subtasks = self.identify_subtasks(task)\n",
        "\n",
        "        print(f\"Identified {len(subtasks)} sub-tasks:\\n\")\n",
        "        for i, subtask in enumerate(subtasks, 1):\n",
        "            print(f\"{i}. {subtask}\")\n",
        "        print()\n",
        "\n",
        "        # Step 2 & 3: Create specialized prompts and solve\n",
        "        print(f\"{'─'*60}\")\n",
        "        print(f\"STEP 2-3: Solving Sub-Tasks with Specialized Prompts\")\n",
        "        print(f\"{'─'*60}\\n\")\n",
        "\n",
        "        results = []\n",
        "\n",
        "        for i, subtask in enumerate(subtasks, 1):\n",
        "            print(f\"📍 Sub-task {i}/{len(subtasks)}: {subtask[:60]}...\")\n",
        "\n",
        "            result = self.solve_subtask(subtask, task, i)\n",
        "            results.append(result)\n",
        "\n",
        "            print(f\"   ✓ Result: {result[:100]}...\")\n",
        "            print(f\"   💾 Stored in memory as 'subtask_{i}'\\n\")\n",
        "\n",
        "        # Show symbolic memory\n",
        "        print(f\"{'─'*60}\")\n",
        "        print(f\"📚 Symbolic Memory State\")\n",
        "        print(f\"{'─'*60}\")\n",
        "        print(self.memory)\n",
        "        print()\n",
        "\n",
        "        # Step 4: Integrate results\n",
        "        print(f\"{'─'*60}\")\n",
        "        print(f\"STEP 4: Integrating Results\")\n",
        "        print(f\"{'─'*60}\\n\")\n",
        "\n",
        "        final_answer = self.integrate_results(task, subtasks, results)\n",
        "\n",
        "        print(f\"{'='*60}\")\n",
        "        print(f\"💡 FINAL ANSWER\")\n",
        "        print(f\"{'='*60}\")\n",
        "        print(final_answer)\n",
        "        print()\n",
        "\n",
        "        return final_answer"
      ],
      "metadata": {
        "id": "c2Q6UiHPZvzU"
      },
      "execution_count": 10,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# Example 1: Complex Math Problem\n",
        "print(\"=\"*60)\n",
        "print(\"EXAMPLE 1: Complex Math Problem\")\n",
        "print(\"=\"*60)\n",
        "\n",
        "agent1 = DecomposedPromptingAgent()\n",
        "agent1.solve(\n",
        "    \"A company's revenue was $500k in Year 1. It grew 20% in Year 2, then decreased 10% in Year 3. \"\n",
        "    \"In Year 4, it grew by the average of Year 2 and Year 3 growth rates. What was the Year 4 revenue? \"\n",
        "    \"Also calculate the total revenue over all 4 years.\"\n",
        ")\n",
        "\n",
        "\n",
        "# Example 2: Multi-Step Reasoning\n",
        "print(\"\\n\" + \"=\"*60)\n",
        "print(\"EXAMPLE 2: Multi-Step Logic Problem\")\n",
        "print(\"=\"*60)\n",
        "\n",
        "agent2 = DecomposedPromptingAgent()\n",
        "agent2.solve(\n",
        "    \"Five people - Alice, Bob, Carol, Dave, and Emma - are standing in a line. \"\n",
        "    \"Alice is not at either end. Bob is between Carol and Dave. Emma is at one end. \"\n",
        "    \"Dave is not next to Emma. What is the order from left to right?\"\n",
        ")\n",
        "\n",
        "\n",
        "# Example 3: Algorithm Design\n",
        "print(\"\\n\" + \"=\"*60)\n",
        "print(\"EXAMPLE 3: Algorithm Design\")\n",
        "print(\"=\"*60)\n",
        "\n",
        "agent3 = DecomposedPromptingAgent()\n",
        "agent3.solve(\n",
        "    \"Design an algorithm to find the second largest element in an unsorted array. \"\n",
        "    \"Explain the approach, write pseudocode, analyze time complexity, and identify edge cases.\"\n",
        ")\n",
        "\n",
        "\n",
        "# Example 4: Scientific Problem\n",
        "print(\"\\n\" + \"=\"*60)\n",
        "print(\"EXAMPLE 4: Scientific Analysis\")\n",
        "print(\"=\"*60)\n",
        "\n",
        "agent4 = DecomposedPromptingAgent()\n",
        "agent4.solve(\n",
        "    \"A ball is thrown upward with initial velocity 20 m/s from a height of 5 meters. \"\n",
        "    \"Calculate: (1) maximum height reached, (2) time to reach max height, \"\n",
        "    \"(3) total time in air, (4) velocity when hitting ground. Use g = 10 m/s².\"\n",
        ")\n",
        "\n",
        "\n",
        "# Example 5: Project Planning\n",
        "print(\"\\n\" + \"=\"*60)\n",
        "print(\"EXAMPLE 5: Project Planning\")\n",
        "print(\"=\"*60)\n",
        "\n",
        "agent5 = DecomposedPromptingAgent()\n",
        "agent5.solve(\n",
        "    \"Plan a company website redesign project with $50k budget and 3-month timeline. \"\n",
        "    \"Identify phases, allocate budget, assign timeline, list deliverables, and identify risks.\"\n",
        ")\n",
        "\n",
        "\n",
        "# Example 6: Code Debugging Workflow\n",
        "print(\"\\n\" + \"=\"*60)\n",
        "print(\"EXAMPLE 6: Debugging Workflow\")\n",
        "print(\"=\"*60)\n",
        "\n",
        "agent6 = DecomposedPromptingAgent()\n",
        "agent6.solve(\n",
        "    \"A Python function to calculate factorial is returning incorrect results for large numbers. \"\n",
        "    \"Diagnose potential issues: check logic, identify edge cases, consider data types, \"\n",
        "    \"suggest fixes, and recommend testing approach.\"\n",
        ")\n",
        "\n",
        "\n",
        "# Example 7: Business Analysis\n",
        "print(\"\\n\" + \"=\"*60)\n",
        "print(\"EXAMPLE 7: Business Analysis\")\n",
        "print(\"=\"*60)\n",
        "\n",
        "agent7 = DecomposedPromptingAgent()\n",
        "agent7.solve(\n",
        "    \"Analyze whether to expand a coffee shop chain into a new city. \"\n",
        "    \"Research market size, estimate costs, project revenue, calculate ROI, \"\n",
        "    \"identify risks, and make a recommendation.\"\n",
        ")\n",
        "\n",
        "\n",
        "# Example 8: Educational Problem\n",
        "print(\"\\n\" + \"=\"*60)\n",
        "print(\"EXAMPLE 8: Educational Exercise\")\n",
        "print(\"=\"*60)\n",
        "\n",
        "agent8 = DecomposedPromptingAgent()\n",
        "agent8.solve(\n",
        "    \"Solve this chemistry problem: How many grams of water are produced when \"\n",
        "    \"10g of hydrogen reacts completely with oxygen? \"\n",
        "    \"Show: balanced equation, molar calculations, stoichiometry, and final answer.\"\n",
        ")\n",
        "\n",
        "\n",
        "print(\"✅ Decomposed Prompting Complete!\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "HMHxPQc1Z3_4",
        "outputId": "4e4826ac-7a8c-4954-95f8-d2620a1b9ee2"
      },
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "============================================================\n",
            "EXAMPLE 1: Complex Math Problem\n",
            "============================================================\n",
            "\n",
            "============================================================\n",
            "🧩 Decomposed Prompting\n",
            "============================================================\n",
            "Task: A company's revenue was $500k in Year 1. It grew 20% in Year 2, then decreased 10% in Year 3. In Year 4, it grew by the average of Year 2 and Year 3 growth rates. What was the Year 4 revenue? Also calculate the total revenue over all 4 years.\n",
            "\n",
            "────────────────────────────────────────────────────────────\n",
            "STEP 1: Identifying Sub-Tasks\n",
            "────────────────────────────────────────────────────────────\n",
            "\n",
            "Identified 5 sub-tasks:\n",
            "\n",
            "1. **Calculate Year 2 Revenue:** Determine the revenue for Year 2 by applying the 20% growth to the Year 1 revenue.\n",
            "2. **Calculate Year 3 Revenue:** Determine the revenue for Year 3 by applying the 10% decrease to the Year 2 revenue.\n",
            "3. **Calculate Average Growth Rate:** Calculate the average of the Year 2 growth rate (20%) and the Year 3 growth rate (-10%).\n",
            "4. **Calculate Year 4 Revenue:** Determine the revenue for Year 4 by applying the average growth rate (calculated in the previous step) to the Year 3 revenue.\n",
            "5. **Calculate Total Revenue:** Sum the revenue from Year 1, Year 2, Year 3, and Year 4 to find the total revenue over the four years.\n",
            "\n",
            "────────────────────────────────────────────────────────────\n",
            "STEP 2-3: Solving Sub-Tasks with Specialized Prompts\n",
            "────────────────────────────────────────────────────────────\n",
            "\n",
            "📍 Sub-task 1/5: **Calculate Year 2 Revenue:** Determine the revenue for Year...\n",
            "   ✓ Result: Year 1 Revenue: $500,000\n",
            "Year 2 Growth Rate: 20%\n",
            "\n",
            "Year 2 Revenue = Year 1 Revenue + (Year 1 Revenue ...\n",
            "   💾 Stored in memory as 'subtask_1'\n",
            "\n",
            "📍 Sub-task 2/5: **Calculate Year 3 Revenue:** Determine the revenue for Year...\n",
            "   ✓ Result: Year 3 Growth Rate: -10%\n",
            "\n",
            "Year 3 Revenue = Year 2 Revenue + (Year 2 Revenue * Year 3 Growth Rate)\n",
            "Ye...\n",
            "   💾 Stored in memory as 'subtask_2'\n",
            "\n",
            "📍 Sub-task 3/5: **Calculate Average Growth Rate:** Calculate the average of ...\n",
            "   ✓ Result: To calculate the average growth rate, we add the Year 2 growth rate and the Year 3 growth rate, and ...\n",
            "   💾 Stored in memory as 'subtask_3'\n",
            "\n",
            "📍 Sub-task 4/5: **Calculate Year 4 Revenue:** Determine the revenue for Year...\n",
            "   ✓ Result: Okay, let's calculate the Year 4 revenue.\n",
            "\n",
            "We know:\n",
            "*   Year 3 Revenue: $540,000\n",
            "*   Average Growth ...\n",
            "   💾 Stored in memory as 'subtask_4'\n",
            "\n",
            "📍 Sub-task 5/5: **Calculate Total Revenue:** Sum the revenue from Year 1, Ye...\n",
            "   ✓ Result: We have the revenue for each of the four years:\n",
            "\n",
            "*   Year 1 Revenue: $500,000\n",
            "*   Year 2 Revenue: $6...\n",
            "   💾 Stored in memory as 'subtask_5'\n",
            "\n",
            "────────────────────────────────────────────────────────────\n",
            "📚 Symbolic Memory State\n",
            "────────────────────────────────────────────────────────────\n",
            "subtask_1: Year 1 Revenue: $500,000\n",
            "Year 2 Growth Rate: 20%\n",
            "\n",
            "Year 2 Revenue = Year 1 Revenue + (Year 1 Revenue * Year 2 Growth Rate)\n",
            "Year 2 Revenue = $500,000 + ($500,000 * 0.20)\n",
            "Year 2 Revenue = $500,000 + $100,000\n",
            "Year 2 Revenue = $600,000\n",
            "\n",
            "**Year 2 Revenue: $600,000**\n",
            "subtask_2: Year 3 Growth Rate: -10%\n",
            "\n",
            "Year 3 Revenue = Year 2 Revenue + (Year 2 Revenue * Year 3 Growth Rate)\n",
            "Year 3 Revenue = $600,000 + ($600,000 * -0.10)\n",
            "Year 3 Revenue = $600,000 - $60,000\n",
            "Year 3 Revenue = $540,000\n",
            "\n",
            "**Year 3 Revenue: $540,000**\n",
            "subtask_3: To calculate the average growth rate, we add the Year 2 growth rate and the Year 3 growth rate, and then divide by 2.\n",
            "\n",
            "Year 2 Growth Rate: 20% = 0.20\n",
            "Year 3 Growth Rate: -10% = -0.10\n",
            "\n",
            "Average Growth Rate = (Year 2 Growth Rate + Year 3 Growth Rate) / 2\n",
            "Average Growth Rate = (0.20 + (-0.10)) / 2\n",
            "Average Growth Rate = (0.10) / 2\n",
            "Average Growth Rate = 0.05\n",
            "\n",
            "Average Growth Rate = 5%\n",
            "\n",
            "**Answer:** The average growth rate is 5%.\n",
            "subtask_4: Okay, let's calculate the Year 4 revenue.\n",
            "\n",
            "We know:\n",
            "*   Year 3 Revenue: $540,000\n",
            "*   Average Growth Rate (Year 4): 5% = 0.05\n",
            "\n",
            "Year 4 Revenue = Year 3 Revenue + (Year 3 Revenue * Average Growth Rate)\n",
            "Year 4 Revenue = $540,000 + ($540,000 * 0.05)\n",
            "Year 4 Revenue = $540,000 + $27,000\n",
            "Year 4 Revenue = $567,000\n",
            "\n",
            "**Answer:** The Year 4 revenue is $567,000.\n",
            "subtask_5: We have the revenue for each of the four years:\n",
            "\n",
            "*   Year 1 Revenue: $500,000\n",
            "*   Year 2 Revenue: $600,000\n",
            "*   Year 3 Revenue: $540,000\n",
            "*   Year 4 Revenue: $567,000\n",
            "\n",
            "To calculate the total revenue, we sum these values:\n",
            "\n",
            "Total Revenue = Year 1 Revenue + Year 2 Revenue + Year 3 Revenue + Year 4 Revenue\n",
            "Total Revenue = $500,000 + $600,000 + $540,000 + $567,000\n",
            "Total Revenue = $2,207,000\n",
            "\n",
            "Therefore, the total revenue over the four years is $2,207,000.\n",
            "\n",
            "**Answer:** The total revenue over the four years is $2,207,000.\n",
            "\n",
            "────────────────────────────────────────────────────────────\n",
            "STEP 4: Integrating Results\n",
            "────────────────────────────────────────────────────────────\n",
            "\n",
            "============================================================\n",
            "💡 FINAL ANSWER\n",
            "============================================================\n",
            "The Year 4 revenue was $567,000. The total revenue over all four years was $2,207,000.\n",
            "\n",
            "\n",
            "============================================================\n",
            "EXAMPLE 2: Multi-Step Logic Problem\n",
            "============================================================\n",
            "\n",
            "============================================================\n",
            "🧩 Decomposed Prompting\n",
            "============================================================\n",
            "Task: Five people - Alice, Bob, Carol, Dave, and Emma - are standing in a line. Alice is not at either end. Bob is between Carol and Dave. Emma is at one end. Dave is not next to Emma. What is the order from left to right?\n",
            "\n",
            "────────────────────────────────────────────────────────────\n",
            "STEP 1: Identifying Sub-Tasks\n",
            "────────────────────────────────────────────────────────────\n",
            "\n",
            "Identified 4 sub-tasks:\n",
            "\n",
            "1. **Identify Definitive Placements:** Determine which person has a confirmed fixed position (e.g., someone is at one end).\n",
            "2. **Analyze Relative Position Constraints:** Break down the \"between\" statement (\"Bob is between Carol and Dave\") into possible arrangement options (Carol-Bob-Dave or Dave-Bob-Carol).\n",
            "3. **Eliminate Arrangement Possibilities:** Use the \"not next to\" statements (\"Alice is not at either end,\" \"Dave is not next to Emma\") to rule out invalid arrangements of the people.\n",
            "4. **Combine Constraints and Solve:** Integrate the information from steps 1-3 to deduce the final order of the people in the line.\n",
            "\n",
            "────────────────────────────────────────────────────────────\n",
            "STEP 2-3: Solving Sub-Tasks with Specialized Prompts\n",
            "────────────────────────────────────────────────────────────\n",
            "\n",
            "📍 Sub-task 1/4: **Identify Definitive Placements:** Determine which person h...\n",
            "   ✓ Result: From the problem statement, we know that \"Emma is at one end\". This definitively places Emma. We don...\n",
            "   💾 Stored in memory as 'subtask_1'\n",
            "\n",
            "📍 Sub-task 2/4: **Analyze Relative Position Constraints:** Break down the \"b...\n",
            "   ✓ Result: The constraint \"Bob is between Carol and Dave\" means that either Carol-Bob-Dave or Dave-Bob-Carol is...\n",
            "   💾 Stored in memory as 'subtask_2'\n",
            "\n",
            "📍 Sub-task 3/4: **Eliminate Arrangement Possibilities:** Use the \"not next t...\n",
            "   ✓ Result: Okay, let's break down this sub-task, eliminating possibilities based on the \"not next to\" constrain...\n",
            "   💾 Stored in memory as 'subtask_3'\n",
            "\n",
            "📍 Sub-task 4/4: **Combine Constraints and Solve:** Integrate the information...\n",
            "   ✓ Result: Okay, let's combine the constraints and find the solution. We know:\n",
            "\n",
            "*   Emma is at one end.\n",
            "*   Eit...\n",
            "   💾 Stored in memory as 'subtask_4'\n",
            "\n",
            "────────────────────────────────────────────────────────────\n",
            "📚 Symbolic Memory State\n",
            "────────────────────────────────────────────────────────────\n",
            "subtask_1: From the problem statement, we know that \"Emma is at one end\". This definitively places Emma. We don't know which end yet, but Emma is either first or last.\n",
            "\n",
            "Therefore, the definitive placement is: **Emma is at one end of the line.**\n",
            "subtask_2: The constraint \"Bob is between Carol and Dave\" means that either Carol-Bob-Dave or Dave-Bob-Carol is a contiguous sequence within the line. There are no other possibilities implied by the word \"between.\"\n",
            "subtask_3: Okay, let's break down this sub-task, eliminating possibilities based on the \"not next to\" constraints.\n",
            "\n",
            "1. **Alice is not at either end:** This means Alice cannot be in the first or last position. This is important because it limits where we can place the Carol-Bob-Dave or Dave-Bob-Carol sequence.\n",
            "\n",
            "2. **Dave is not next to Emma:** This is the most powerful constraint for this sub-task. Let's consider both possibilities for Emma's placement:\n",
            "\n",
            "   * **Case 1: Emma is first:** If Emma is in the first position, Dave *cannot* be in the second position. This severely limits the arrangements that include the \"Bob is between Carol and Dave\" condition.  It means that if Emma is at the beginning, the sequence \"Dave-Bob-Carol\" cannot start at the beginning. We know Bob is between Carol and Dave, so if Emma is first, Dave can't be second.\n",
            "\n",
            "   * **Case 2: Emma is last:**  If Emma is in the last position, Dave *cannot* be in the fourth position (the position immediately to the left of Emma). Similar to the above, this restricts arrangements containing \"Bob is between Carol and Dave.\" If Emma is last, Dave cannot be in the 4th position.\n",
            "**Summary of Eliminations:**\n",
            "\n",
            "*   If Emma is first, Dave cannot be in the second position.\n",
            "*   If Emma is last, Dave cannot be in the fourth position.\n",
            "subtask_4: Okay, let's combine the constraints and find the solution. We know:\n",
            "\n",
            "*   Emma is at one end.\n",
            "*   Either Carol-Bob-Dave or Dave-Bob-Carol is a sequence.\n",
            "*   Alice is not at either end.\n",
            "*   Dave is not next to Emma.\n",
            "\n",
            "Let's consider the two cases for Emma:\n",
            "\n",
            "**Case 1: Emma is first (Emma _ _ _ _)**\n",
            "\n",
            "If Emma is first, Dave cannot be second. So, the sequence Dave-Bob-Carol can't start in the first two positions. Let's see where Dave-Bob-Carol can fit:\n",
            "\n",
            "*   If Dave-Bob-Carol starts in the 3rd position, we have: Emma _ _ Dave Bob Carol.  Alice must be placed in one of the remaining spots. Since Alice cannot be at either end, Alice must be in the 2nd spot: Emma Alice Dave Bob Carol. This satisfies all conditions.\n",
            "\n",
            "**Case 2: Emma is last (_ _ _ _ Emma)**\n",
            "\n",
            "If Emma is last, Dave cannot be in the fourth position. So, the sequence Carol-Bob-Dave can't end in the last two positions. Let's see where it can fit:\n",
            "\n",
            "*If Carol-Bob-Dave starts in position 1 we have Carol-Bob-Dave _ Emma. Alice must be in the open spot: Carol Bob Dave Alice Emma. This works\n",
            "\n",
            "*if Dave-Bob-Carol starts in position 1 we have Dave-Bob-Carol _ Emma. Alice must be in the open spot: Dave Bob Carol Alice Emma. This works.\n",
            "\n",
            "Therefore, we have several possible answers:\n",
            "\n",
            "* Emma Alice Dave Bob Carol\n",
            "* Carol Bob Dave Alice Emma\n",
            "* Dave Bob Carol Alice Emma\n",
            "\n",
            "────────────────────────────────────────────────────────────\n",
            "STEP 4: Integrating Results\n",
            "────────────────────────────────────────────────────────────\n",
            "\n",
            "============================================================\n",
            "💡 FINAL ANSWER\n",
            "============================================================\n",
            "Okay, let's analyze the possible solutions we derived and see if we can narrow it down further.\n",
            "\n",
            "We have three potential solutions:\n",
            "\n",
            "1.  **Emma Alice Dave Bob Carol**\n",
            "2.  **Carol Bob Dave Alice Emma**\n",
            "3.  **Dave Bob Carol Alice Emma**\n",
            "\n",
            "Let's re-examine the constraints:\n",
            "\n",
            "*   Emma is at one end. (All three solutions satisfy this)\n",
            "*   Either Carol-Bob-Dave or Dave-Bob-Carol is a sequence. (All three solutions satisfy this)\n",
            "*   Alice is not at either end. (All three solutions satisfy this)\n",
            "*   Dave is not next to Emma. (All three solutions satisfy this)\n",
            "\n",
            "Since all three solutions satisfy all the constraints, there is no further way to definitively determine the order based on the given information.\n",
            "\n",
            "**Final Answer:**\n",
            "\n",
            "The possible orders from left to right are:\n",
            "\n",
            "*   Emma Alice Dave Bob Carol\n",
            "*   Carol Bob Dave Alice Emma\n",
            "*   Dave Bob Carol Alice Emma\n",
            "\n",
            "\n",
            "============================================================\n",
            "EXAMPLE 3: Algorithm Design\n",
            "============================================================\n",
            "\n",
            "============================================================\n",
            "🧩 Decomposed Prompting\n",
            "============================================================\n",
            "Task: Design an algorithm to find the second largest element in an unsorted array. Explain the approach, write pseudocode, analyze time complexity, and identify edge cases.\n",
            "\n",
            "────────────────────────────────────────────────────────────\n",
            "STEP 1: Identifying Sub-Tasks\n",
            "────────────────────────────────────────────────────────────\n",
            "\n",
            "Identified 5 sub-tasks:\n",
            "\n",
            "1. **Approach & Algorithm Explanation:**  Clearly define the algorithm strategy. Explain the logic behind how you will find the second largest element (e.g., single pass, multiple passes, comparisons). Describe the steps in plain English.\n",
            "2. **Pseudocode Development:**  Translate the explained algorithm into detailed pseudocode. The pseudocode should be detailed enough to be easily translated into actual code in any programming language.\n",
            "3. **Edge Case Identification & Handling:** Identify potential edge cases (e.g., empty array, array with only one element, array with duplicate largest elements).  Describe how the algorithm will handle each of these scenarios to avoid errors and produce correct results (or a sensible indication of failure).\n",
            "4. **Time Complexity Analysis:**  Analyze the time complexity of the algorithm.  Explain the Big O notation (e.g., O(n), O(n log n), O(n^2)) and provide a justification for why the algorithm has that complexity.\n",
            "5. **Pseudocode Refinement:** Improve your Pseudocode by considering the edge-cases you have defined.\n",
            "\n",
            "────────────────────────────────────────────────────────────\n",
            "STEP 2-3: Solving Sub-Tasks with Specialized Prompts\n",
            "────────────────────────────────────────────────────────────\n",
            "\n",
            "📍 Sub-task 1/5: **Approach & Algorithm Explanation:**  Clearly define the al...\n",
            "   ✓ Result: Okay, here's the approach and algorithm explanation for finding the second largest element in an uns...\n",
            "   💾 Stored in memory as 'subtask_1'\n",
            "\n",
            "📍 Sub-task 2/5: **Pseudocode Development:**  Translate the explained algorit...\n",
            "   ✓ Result: ```pseudocode\n",
            "FUNCTION findSecondLargest(arr):\n",
            "  // Input: An array 'arr' of numbers\n",
            "  // Output: Th...\n",
            "   💾 Stored in memory as 'subtask_2'\n",
            "\n",
            "📍 Sub-task 3/5: **Edge Case Identification & Handling:** Identify potential ...\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "WARNING:tornado.access:429 POST /v1beta/models/gemini-2.0-flash-exp:generateContent?%24alt=json%3Benum-encoding%3Dint (127.0.0.1) 456.02ms\n"
          ]
        },
        {
          "output_type": "error",
          "ename": "TooManyRequests",
          "evalue": "429 POST https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?%24alt=json%3Benum-encoding%3Dint: You exceeded your current quota. Please migrate to Gemini 2.0 Flash Preview (Image Generation) (models/gemini-2.0-flash-preview-image-generation) for higher quota limits. For more information on this error, head to: https://ai.google.dev/gemini-api/docs/rate-limits.",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mTooManyRequests\u001b[0m                           Traceback (most recent call last)",
            "\u001b[0;32m/tmp/ipython-input-2480236460.py\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[1;32m     31\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     32\u001b[0m \u001b[0magent3\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mDecomposedPromptingAgent\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 33\u001b[0;31m agent3.solve(\n\u001b[0m\u001b[1;32m     34\u001b[0m     \u001b[0;34m\"Design an algorithm to find the second largest element in an unsorted array. \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     35\u001b[0m     \u001b[0;34m\"Explain the approach, write pseudocode, analyze time complexity, and identify edge cases.\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/tmp/ipython-input-4277361195.py\u001b[0m in \u001b[0;36msolve\u001b[0;34m(self, task)\u001b[0m\n\u001b[1;32m    119\u001b[0m             \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"📍 Sub-task {i}/{len(subtasks)}: {subtask[:60]}...\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    120\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 121\u001b[0;31m             \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msolve_subtask\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msubtask\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtask\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    122\u001b[0m             \u001b[0mresults\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    123\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/tmp/ipython-input-4277361195.py\u001b[0m in \u001b[0;36msolve_subtask\u001b[0;34m(self, subtask, task_context, subtask_id)\u001b[0m\n\u001b[1;32m     62\u001b[0m         \u001b[0mspecialized_prompt\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate_specialized_prompt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msubtask\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtask_context\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     63\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 64\u001b[0;31m         \u001b[0mresponse\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgenerate_content\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mspecialized_prompt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     65\u001b[0m         \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstrip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     66\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/google/generativeai/generative_models.py\u001b[0m in \u001b[0;36mgenerate_content\u001b[0;34m(self, contents, generation_config, safety_settings, stream, tools, tool_config, request_options)\u001b[0m\n\u001b[1;32m    329\u001b[0m                 \u001b[0;32mreturn\u001b[0m \u001b[0mgeneration_types\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGenerateContentResponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_iterator\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    330\u001b[0m             \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 331\u001b[0;31m                 response = self._client.generate_content(\n\u001b[0m\u001b[1;32m    332\u001b[0m                     \u001b[0mrequest\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    333\u001b[0m                     \u001b[0;34m**\u001b[0m\u001b[0mrequest_options\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/google/ai/generativelanguage_v1beta/services/generative_service/client.py\u001b[0m in \u001b[0;36mgenerate_content\u001b[0;34m(self, request, model, contents, retry, timeout, metadata)\u001b[0m\n\u001b[1;32m    833\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    834\u001b[0m         \u001b[0;31m# Send the request.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 835\u001b[0;31m         response = rpc(\n\u001b[0m\u001b[1;32m    836\u001b[0m             \u001b[0mrequest\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    837\u001b[0m             \u001b[0mretry\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mretry\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/google/api_core/gapic_v1/method.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, timeout, retry, compression, *args, **kwargs)\u001b[0m\n\u001b[1;32m    129\u001b[0m             \u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"compression\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcompression\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    130\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 131\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mwrapped_func\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    132\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    133\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/google/api_core/retry/retry_unary.py\u001b[0m in \u001b[0;36mretry_wrapped_func\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    292\u001b[0m                 \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_initial\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_maximum\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmultiplier\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_multiplier\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    293\u001b[0m             )\n\u001b[0;32m--> 294\u001b[0;31m             return retry_target(\n\u001b[0m\u001b[1;32m    295\u001b[0m                 \u001b[0mtarget\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    296\u001b[0m                 \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_predicate\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/google/api_core/retry/retry_unary.py\u001b[0m in \u001b[0;36mretry_target\u001b[0;34m(target, predicate, sleep_generator, timeout, on_error, exception_factory, **kwargs)\u001b[0m\n\u001b[1;32m    154\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    155\u001b[0m             \u001b[0;31m# defer to shared logic for handling errors\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 156\u001b[0;31m             next_sleep = _retry_error_helper(\n\u001b[0m\u001b[1;32m    157\u001b[0m                 \u001b[0mexc\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    158\u001b[0m                 \u001b[0mdeadline\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/google/api_core/retry/retry_base.py\u001b[0m in \u001b[0;36m_retry_error_helper\u001b[0;34m(exc, deadline, sleep_iterator, error_list, predicate_fn, on_error_fn, exc_factory_fn, original_timeout)\u001b[0m\n\u001b[1;32m    212\u001b[0m             \u001b[0moriginal_timeout\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    213\u001b[0m         )\n\u001b[0;32m--> 214\u001b[0;31m         \u001b[0;32mraise\u001b[0m \u001b[0mfinal_exc\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0msource_exc\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    215\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mon_error_fn\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    216\u001b[0m         \u001b[0mon_error_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mexc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/google/api_core/retry/retry_unary.py\u001b[0m in \u001b[0;36mretry_target\u001b[0;34m(target, predicate, sleep_generator, timeout, on_error, exception_factory, **kwargs)\u001b[0m\n\u001b[1;32m    145\u001b[0m     \u001b[0;32mwhile\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    146\u001b[0m         \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 147\u001b[0;31m             \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtarget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    148\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0minspect\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0misawaitable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    149\u001b[0m                 \u001b[0mwarnings\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwarn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_ASYNC_RETRY_WARNING\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/google/api_core/timeout.py\u001b[0m in \u001b[0;36mfunc_with_timeout\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    128\u001b[0m                 \u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"timeout\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mremaining_timeout\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    129\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 130\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    131\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    132\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mfunc_with_timeout\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/google/api_core/grpc_helpers.py\u001b[0m in \u001b[0;36merror_remapped_callable\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m     73\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0merror_remapped_callable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     74\u001b[0m         \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 75\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mcallable_\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     76\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0mgrpc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mRpcError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     77\u001b[0m             \u001b[0;32mraise\u001b[0m \u001b[0mexceptions\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_grpc_error\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mexc\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mexc\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/google/ai/generativelanguage_v1beta/services/generative_service/transports/rest.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, request, retry, timeout, metadata)\u001b[0m\n\u001b[1;32m   1159\u001b[0m             \u001b[0;31m# subclass.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1160\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstatus_code\u001b[0m \u001b[0;34m>=\u001b[0m \u001b[0;36m400\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1161\u001b[0;31m                 \u001b[0;32mraise\u001b[0m \u001b[0mcore_exceptions\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_http_response\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresponse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1162\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1163\u001b[0m             \u001b[0;31m# Return the response\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;31mTooManyRequests\u001b[0m: 429 POST https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?%24alt=json%3Benum-encoding%3Dint: You exceeded your current quota. Please migrate to Gemini 2.0 Flash Preview (Image Generation) (models/gemini-2.0-flash-preview-image-generation) for higher quota limits. For more information on this error, head to: https://ai.google.dev/gemini-api/docs/rate-limits."
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "iXI_TGOCaByF"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}